/**
 * 
 */
package com.dianba.commons.exception.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.util.StringUtils;

/**
 *
 *
 * @author zhoucong
 * @date 2016年4月30日 下午2:58:47
 */
public class LoggerWapper {
	private final Log log;

	public LoggerWapper(Class<?> clazz) {
		log = LogFactory.getLog(clazz);
	}

	public void debug(String message, Throwable e) {
		message = formatMsg(message);
		log.debug(message, e);
	}

	public void info(String message) {
		message = formatMsg(message);
		log.info(message);
	}

	public void warn(String message) {
		message = formatMsg(message);
		log.warn(message);
	}

	public void error(String message) {
		message = formatMsg(message);
		log.error(message);
	}

	public void info(String message, Throwable e) {
		message = formatMsg(message);
		log.info(message, e);
	}

	public void warn(String message, Throwable e) {
		message = formatMsg(message);
		log.warn(message, e);
	}

	public void error(String message, Throwable e) {
		message = formatMsg(message);
		log.error(message, e);
	}

	private String formatMsg(String message) {
		if (StringUtils.isEmpty(ThreadContent.getSerialVersionMsg())) {
			message = "serialVersionMsg:" + ThreadContent.getSerialVersionMsg() + message;
		}
		return message;
	}

	public boolean isDebugEnabled() {
		return log.isDebugEnabled();
	}

	public boolean isErrorEnabled() {
		return log.isErrorEnabled();
	}

	public boolean isWarnEnabled() {
		return log.isWarnEnabled();
	}

	public boolean isInfoEnabled() {
		return log.isInfoEnabled();
	}

	public void info(Object... objects) {
		if (isInfoEnabled()) {
			StringBuilder sb = new StringBuilder();
			for (Object object : objects) {
				sb.append(object).append(" , ");
			}
			info(sb.toString());
		}
	}
}
